package com.lanju.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.lanju.entity.User;
import com.lanju.service.ServiceCommentService;
import com.lanju.util.ServletUtil;

@Controller
@RequestMapping("serviceComment")
public class ServiceCommentController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCommentController.class);
	
	@Autowired
	ServiceCommentService serviceCommentService;
	
	@RequestMapping("insertServiceComment")
	@ResponseBody
	public Map<String,Object> insertServiceComment(HttpServletRequest request,HttpSession session){
		Map<String, Object> param = ServletUtil.getParameterMap(request);
		JSONObject json = JSONObject.parseObject(JSONObject.toJSONString(param));
		User user =(User) session.getAttribute("userModel");
		if(user == null){
			Map<String,Object> result=new HashMap<String, Object>();
			result.put("success", false);
			result.put("msg", "用户尚未登录");
		}
		param.put("userId", user.getUserId());
		return serviceCommentService.insertServiceComment(param);
	}
	
	@RequestMapping("getCommentList")
	@ResponseBody
	public Map<String,Object> getCommentList(HttpServletRequest request,HttpSession session){
		Map<String, Object> param = ServletUtil.getParameterMap(request);
		return serviceCommentService.getCommentList(param);
	}

}
